KindEditor.ready(function(K) {
	var editor = K.editor({
		allowFileManager : true,
		fileManagerJson : kindeditor_pre_url+'/jsp/file_manager_json.jsp'
	});
	
	
	editor = K.create('textarea[class="js-textarea-editor"]', {
			urlType : 'domain',
			resizeType : 1,
			allowPreviewEmoticons : false,
			allowImageUpload : true,
			afterBlur : function() {
				this.sync();
			},
			items : [
				'source','fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
				'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
				'insertunorderedlist', '|', 'emoticons', 'image','multiimage', 'link','fullscreen']
	});
	
	K('.js-insertfile').click(function() {
		var relation_input_name=K(this).attr("relation_input_name");
		editor.loadPlugin('insertfile', function() {
			editor.plugin.fileDialog({
				fileUrl : K('#u'+relation_input_name).val(),
				clickFn : function(url, title) {
					//K('#url').val(url);
					$('#'+relation_input_name).textbox("setValue", url);
					editor.hideDialog();
				}
			});
		});
	});
	
	K('.js-insertfile-mutil').click(function() {
		var relation_input_name=K(this).attr("relation_input_name");
		var num = K(this).attr("num");
		editor.loadPlugin('insertfile', function() {
			editor.plugin.fileDialog({
				fileUrl : K('#u'+relation_input_name).val(),
				clickFn : function(url, title) {
					//K('#url').val(url);
					$('#'+relation_input_name+'_'+num).textbox("setValue", url);
					editor.hideDialog();
				}
			});
		});
	});
	
	K('.js-filemanager').click(function() {
		var relation_input_name=K(this).attr("relation_input_name");
		editor.loadPlugin('filemanager', function() {
			editor.plugin.filemanagerDialog({
				viewType : 'VIEW',
				dirName : 'image',
				clickFn : function(url, title) {
					$('#'+relation_input_name).textbox("setValue", url);
					$('#'+relation_input_name+'_img').html("");
					$('#'+relation_input_name+'_img').append("<a href='"+url+"' target='view_window'> <img src='"+url+"' width='100' height='100'></a>");
					//K('#url').val(url);
					editor.hideDialog();
				}
			});
		});
	});
	K('.js-filemanager-mutil').click(function() {
		var relation_input_name=K(this).attr("relation_input_name");
		var num = K(this).attr("num");
		editor.loadPlugin('filemanager', function() {
			editor.plugin.filemanagerDialog({
				viewType : 'VIEW',
				dirName : 'image',
				clickFn : function(url, title) {
					$('#'+relation_input_name+'_'+num).textbox("setValue", url);
					//$('#'+relation_input_name+'_img').html("");
					$('#'+relation_input_name+'_img').append("<a href='"+url+"' target='view_window'> <img src='"+url+"' width='100' height='100'></a>");
					//K('#url').val(url);
					editor.hideDialog();
				}
			});
		});
	});
});